package com.javasm.commons.base;

import com.github.pagehelper.PageHelper;
import com.javasm.commons.entity.AxiosResult;
import com.javasm.commons.entity.TableDatas;
import com.javasm.commons.util.ServletUtils;

import java.util.List;

public class BaseController {
    private static final String PAGE_NUM="pageNum";
    private static final String PAGE_SIZE="pageSize";

    public static void startPage(){
        Integer pageNum = ServletUtils.getParameter(PAGE_NUM, 1);
        Integer pageSize = ServletUtils.getParameter(PAGE_SIZE, 10);
        PageHelper.startPage(pageNum,pageSize);
    }

    public AxiosResult isok(boolean b){
        if(b)return AxiosResult.suc();
        return AxiosResult.error();
    }

    public TableDatas toTableDatas(List list){
        return new TableDatas(list);
    }

    public AxiosResult suc(Object data){
        return AxiosResult.suc(data);
    }

    public AxiosResult suc(){
        return AxiosResult.suc();
    }
}
